package io.sxl.modules.generator.controller;

import io.sxl.common.utils.R;
import io.sxl.modules.generator.entity.HouseEntity;
import io.sxl.modules.generator.entityx.DiaoBoEntity;
import io.sxl.modules.generator.entityx.ProIdandName;
import io.sxl.modules.generator.service.HouseService;
import io.sxl.modules.generator.service.ProjectService;
import io.sxl.modules.generator.service.impl.DiaoboService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("diaobo/diaobo")
@Slf4j
public class DbfpController {
    @Resource
    private DiaoboService diaoboservice;

    @Resource
    private ProjectService projectService;

    @Resource
    private HouseService houseService;


    /**
     * 根据前台传递过来的工程id和房屋id
     * 来完成房屋的分配（将房屋的project_id置为传递过来的工程id）
     */
    @RequestMapping("/diaobo")
    @RequiresPermissions("generator:fangyuan:diaobo")
    public R diaobo(@RequestBody DiaoBoEntity map) {
        List<HouseEntity> id = map.getId();
        System.out.println(id);
        String diaobo = diaoboservice.diaobo(map);
        System.out.println("diaobo = " + diaobo);
        return R.ok();
    }

    /**
     * 查询工程的id和name并且只返回这两个数据
     */
    @RequestMapping("/idandname")
    //@RequiresPermissions("generator:fangyuan:diaobo")
    public R getProjectIdandName() {
        List<ProIdandName> idandNames = projectService.queryIdandName();
        return R.ok().put("data", idandNames);
    }

    /**
     * 查询工程的id和name并且只返回这两个数据
     */
    @RequestMapping("/fenpei")
    @RequiresPermissions("generator:fangyuan:fenpei")
    public R fenpei(@RequestParam Map<String, Object> map, @CookieValue("token") String token) {
        map.forEach((k, v) -> System.out.println(k + ":" + v));

        Boolean fenpei = diaoboservice.fenpei(map);
        if (fenpei){
            return R.ok();
        } else {
            return R.error("未知错误");
        }
    }







    @RequestMapping("/test")
    //@RequiresPermissions("generator:fangyuan:diaobo")
    public R test(HttpServletRequest request) {
        StringBuffer requestURL = request.getRequestURL();

        System.out.println("requestURL = " + requestURL);
        return  new R();
    }

}
